package com.cloud.note.repository;

import com.cloud.note.model.Favorite;
import com.cloud.note.model.FavoriteId;
import com.cloud.note.model.Note;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface FavoriteRepository extends JpaRepository<Favorite, FavoriteId> {

    @Query("SELECT f.note FROM Favorite f WHERE f.userId = :userId AND f.note.isTrashed = false")
    Page<Note> findFavoriteNotes(@Param("userId") String userId, Pageable pageable);

    boolean existsByUserIdAndNoteId(String userId, String noteId);

    void deleteByUserIdAndNoteId(String userId, String noteId);
}